<?php
/**
 * Created by PhpStorm.
 * User: bxm
 * Date: 2022/6/28
 * Time: 0:38
 */

namespace app\api\controller\worker;

use app\api\controller\Base;
use app\common\model\worker\SaleWayDataModel;

class SaleWayDataController  extends Base
{
    private $model;
    /**
     * 构造方法
     * @access public
     * @throws \Exception
     */
    public function __construct()
    {

        parent::__construct();
        $this->checkLogin();
        $this->model = new SaleWayDataModel();

    }
    public function list(){
        $data = $this->request->param();
        $customer_id  = $data['customer_id'];
        $pageSize      = $this->request->param('pageSize/d', 20); //每页多少条
        $pageNumber    = $this->request->param('pageNumber/d') ?? 1; //当前页

        $list = $this->model
            ->where('customer_id',$customer_id)->order('id','desc')->paginate($pageSize, false, ['page' =>$pageNumber ]);



        $this->result($list,'操作成功',1);
    }
    public function add(){
        $roles_ids = $this->role_ids;
        if(!in_array(6,$roles_ids) ||!in_array(7,$roles_ids) || !in_array(8,$roles_ids)  ){

            $this->result([],'该用户没有权限，只有设计师，业务员，客户代表有操作权限！',0);
        }
        $param = $this->request->param();
        $rule = [
            'content|销售策略'=>'require',
            'customer_id|客户id'=>'require',
        ];
        $this->validate($param,$rule);
        $data = [
            'customer_id' => $param['customer_id'],
            'content' => $param['content'],
        ];
        $data['action_admin_id'] = $this->loginInfo['id'];
        $info = $this->model->add($data);
        $this->result($info,'操作成功',1);
    }

}